<template>
  <a-card :bordered="false" class="withdrawal">
    <a-tabs default-active-key="10" @change="callback">
      <a-tab-pane :key="item" :tab="index" v-for="index,item in tabs"></a-tab-pane>
    </a-tabs>
    <section>
      <div class="theknightSearch table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="getList">
          <a-row :gutter="24">
            <a-col :md="5" :sm="5">
              <a-form-item label="订单号" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
                <a-input placeholder="请输入订单号" v-model="queryParam.orderNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="12">
              <a-form-item label="支付时间" :labelCol="{span: 2}" :wrapperCol="{span: 18, offset: 1}">
                <section class="time-box">
                  <j-date v-model="queryParam.payTimeFrom" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss"
                    style="width:43%;min-width:0;" placeholder="开始时间"></j-date>
                  <span style="felx:1"> - </span>
                  <j-date v-model="queryParam.payTimeTo" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss"
                    style="width:43%;min-width:0;" placeholder="结束时间"></j-date>
                </section>
              </a-form-item>
            </a-col>
            <a-col :md="5" :sm="5">
              <a-button style="margin-left: 8px" @click="getList">搜索</a-button>
              <a-button style="margin-left: 8px" @click="onClose">刷新</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <section class="table">
        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :pagination="ipagination"
          @change="changePage" :dataSource="List" :loading="loading">
          <span slot="action" slot-scope="text, record">
            <a href="javaScript:;" v-if="queryParam.status==1||queryParam.status==2" @click="editor(record,1)"
              v-has="'Take:audit'">审核</a>
            <a href="javaScript:;" v-if="queryParam.status==-1" @click="editor(record,-1)">原因</a>
            <a-divider type="vertical" />
            <a-dropdown v-has="'Take:sensitive'" v-if="queryParam.status==1||queryParam.status==2">
              <a class="ant-dropdown-link">更多
                <a-icon type="down" />
              </a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a href="javaScript:;" v-if="queryParam.status==1||queryParam.status==2"
                    @click="editor(record,2)">修改</a>
                </a-menu-item>
                <a-menu-item>
                  <a href="javaScript:;" @click="editor(record,3)">删除</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>
          <template slot="expandedRowRender" slot-scope="record,index">
            <a-table rowKey="id" :columns="innerColumns" :dataSource="record.financeLines" :pagination="false">
            </a-table>
          </template>
        </a-table>
      </section>
      <a-modal v-model="visible" title="修改提现信息" @ok="handleOk">
        <a-form-item label="支付宝账号" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
          <a-input v-model="infoData.alipayAccount"></a-input>
        </a-form-item>
        <a-form-item label="支付宝实名认证姓名" :labelCol="{span: 7}" :wrapperCol="{span: 14, offset: 1}">
          <a-input v-model="infoData.alipayName"></a-input>
        </a-form-item>
      </a-modal>
      <a-modal v-model="showWhy" title="驳回原因" @ok="showWhy=false" @cancel='onClose'>
        <p>{{infoData.rejectReason}}</p>
      </a-modal>
      <a-modal v-model="showDelete" title="删除提现记录" @ok="deleteOk" @cancel='onClose'>
        <p>删除后，提现记录下的提现状态都会改回「待提现」</p>
      </a-modal>
      <a-modal v-model="showTransfer" title="转账" @ok="TransferOk" @cancel='onClose'>
        <p>确认是否转账</p>
      </a-modal>
      <a-modal v-model="showAudit" title="审核" @ok="auditeOk" @cancel='onClose'>
        <a-radio-group v-model="adio">
          <a-radio :value='1'>审核通过</a-radio>
          <a-radio :value='2'>审核驳回</a-radio>
        </a-radio-group>
        <a-form-item style="margin-top:20px" v-if="adio==2" label="驳回原因" :labelCol="{span: 4}"
          :wrapperCol="{span: 14, offset: 1}">
          <a-textarea v-model="infoData.rejectReason"></a-textarea>
        </a-form-item>
      </a-modal>
    </section>
  </a-card>

</template>
<script>
import {
  postAction,
  getAction
} from '@/api/manage'
import { deleteAction, putAction } from '../../api/manage'
export default {
  data() {
    return {
      adio: '1',
      showTransfer: false,
      showWhy: false,
      showDelete: false,
      showAudit: false,
      visible: false,
      tabs: {},
      loading: false,
      queryParam: {
        status: 1,
        pageNo: 1,
      },
      substationList: [],// 分站列表
      updStatus: {},
      List: [],
      infoList: [], //登录历史数据
      infoData: {},//选中数据
      selectedRowKeysArrey: [], //选中的id
      chooseOrder: '', // 选中的数据
      isBranchFlag: false,// 当前登录用户是否分站用户
      columns: [
        {
          title: '提现组编号',
          align: "center",
          dataIndex: 'groupNo',
        },
        {
          title: '名称',
          align: "center",
          dataIndex: 'siteId_dictText',
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
        },
        {
          title: '修改时间',
          align: "center",
          dataIndex: 'updateTime',
        },
        {
          title: '提现总金额',
          align: "center",
          dataIndex: 'totalAmount',
        },
        {
          title: '提现类型',
          align: "center",
          dataIndex: 'type',
          customRender: function (t, r, index) {
            let color
            switch (t) {
              case 1:
                color = '商家'
                break
              case 2:
                color = '分站'
                break
            }
            return color
          }
        },
        {
          title: '提现状态',
          align: "center",
          dataIndex: 'status',
          customRender: function (t, r, index) {
            let color
            switch (t) {
              case 1:
                color = '待审核'
                break
              case 2:
                color = '待转账'
                break
              case 2:
                color = '已提现'
                break
              case -1:
                color = '驳回'
                break
              case -2:
                color = '转账失败'
                break
            }
            return color
          }
        },
        {
          title: '支付宝账号',
          align: "center",
          dataIndex: 'alipayAccount',
        },
        {
          title: '支付宝实名认证姓名',
          align: "center",
          dataIndex: 'alipayName',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      innerColumns: [
        {
          title: '订单编号',
          align: "center",
          dataIndex: 'orderNo',
        },
        {
          title: '订单支付金额',
          align: "center",
          dataIndex: 'payAmount',
        },
        {
          title: '订单支付时间',
          align: "center",
          dataIndex: 'payTime',
        }
      ],
      //标记页数；页码
      ipagination: {
        current: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        total: 0
      },
      url: {
        tbas: '/financeGroup/status',
        List: '/financeGroup/page',
        pct: '/financeGroup/updateAlipay',
        delete: '/financeGroup/delete',
        updateAlipay: '/financeGroup/updateAlipay',
        audit: '/financeGroup/audit',
        transfer: '/financeGroup/transfer',
      }
    }
  },
  created() {
    this.getTabs()
    this.getList()
  },
  methods: {
    TransferOk() {
      putAction(this.url.transfer + this.infoData.id).then(res => {
        console.log(res)
        if (res.code == 200) {
          this.showTransfer = false
          this.$message.success('成功')
        } else {
          this.showTransfer = false
        }
        this.getList()
      })
    },
    auditeOk() {
      console.log(this.adio)
      if (this.adio != '') {
        if (this.adio == 1) {
          this.infoData.isPass = true
        } else {
          this.infoData.isPass = false
        }
        putAction(this.url.audit + '?id=' + this.infoData.id + '&isPass=' + this.infoData.isPass + '&rejectReason=' + this.infoData.rejectReason).then(res => {
          console.log(res)
          if (res.code == 200) {
            this.$message.success('成功')
            this.showAudit = false
          } else {
            this.showDelete = false
          }
          this.getList()
        })
      } else {
        this.$message.warning('未选择')
      }

    },
    deleteOk() {
      if (this.infoData.deletable) {
        deleteAction(this.url.delete + this.infoData.id).then(res => {
          if (res.code == 200) {
            this.showDelete = false
          } else {
            this.showDelete = false
          }
          this.getList()
          console.log(res)
        })
      } else {
        this.$message.warning("不能删除")
      }
    },
    handleOk() {
      putAction(this.url.pct, this.infoData).then(res => {
        console.log(res)
        if (res.code == 200) {
          this.visible = false
        } else {
          this.visible = false
        }
        this.getList()
      })
    },
    editor(e, y) {
      this.infoData = e
      if (y == 1) {
        if (this.queryParam.status == 1) {
          this.showAudit = true
        } else {
          this.showTransfer = true
        }
      }
      if (y == 2) {
        this.visible = true
      }
      if (y == 3) {
        this.showDelete = true
      }
      if (y == -1) {
        this.showWhy = true
      }

    },
    // 查询分站
    getTabs() {
      getAction(this.url.tbas).then(res => {
        this.tabs = res.result
        console.log(this.tabs)
      })
    },
    callback(key) {
      console.log(key)
      this.queryParam.status = key
      this.queryParam.pageNo = 1
      this.ipagination.current = 1
      this.getList()
      // this.queryParam.pageNo = 1;
      // this.queryParam.pageSize = 10;
      // this.ipagination.current = 1
      // this.queryParam.status = key
      // this.getList()
      // console.log("当前选中的tabs", this.queryParam, "当前查询参数");
      // this.chooseOrder = ''
      // this.selectedRowKeysArrey = []
    },
    getList() {
      this.loading = true
      postAction(this.url.List + '?pageNo=' + this.queryParam.pageNo, this.queryParam).then(res => {
        console.log(res, "记录");
        if (res.success) {
          this.loading = false
        }
        this.List = res.result.records
        this.ipagination.total = res.result.total;  // 页数
      })
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    onClose() {
      this.adio = '1'
      this.selectedRowKeysArrey = []
      this.chooseOrder = ""
      this.queryParam.orderNo = ''
      this.queryParam.payTimeFrom = ''
      this.queryParam.payTimeTo = ''
      this.getList()
    },
    // 选中一行
    onSelectChange(a, b) {
      this.selectedRowKeysArrey = a;
      this.chooseOrder = b[0];
      console.log(this.chooseOrder, "选中的数据");
      this.add = this.chooseOrder
      this.infoData = this.chooseOrder
    },
    // 代理列表改变分页
    changePage(pagination) {
      this.ipagination.current = pagination.current
      console.log(pagination);
      this.queryParam.pageNo = pagination.current;
      this.queryParam.pageSize = pagination.pageSize;
      this.getList();
    }
  }
}
</script>
<style lang="less" scoped>
.withdrawal {
  .time {
    margin-top: 30px;
  }

  .theknightSearch {
    margin-top: -15px;
    padding: 15px 10px;

    .ant-form-item {
      width: 100%;
    }
  }

  .table-page-search-wrapper .ant-form-inline .ant-form-item {
    margin-bottom: 0px !important;
  }
}

.btn {
  button {
    margin-right: 10px;
  }
}
</style>